import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/2/21 15:07
 * @description 身高从高到低排序
 */
public class FormalSolution2 {
    public static void main(String[] args) {
        FormalSolution2 solution = new FormalSolution2();
        int[][] people = {{7, 0}, {4, 4}, {7,1}, {5, 0}, {6, 1}, {5, 2}};
        solution.reconstructQueue(people);
    }
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, (o1, o2) -> {
            if (o1[0] != o2[0]) {
                //身高不等，按身高降序排
                return o2[0] - o1[0];
            }else {
                // 身高相等，按人数升序排
                return o1[1] - o2[1];
            }
        });
        List<int[]> ans = new ArrayList<>();
        for (int[] person: people) {
            ans.add(person[1], person);
        }
        return ans.toArray(new int[ans.size()][]);
    }
}
